# -*- encoding: utf-8 -*-
"""
File Name: handle_subscribe_info_util
Description:
Author : 'lirui'
date: 11/1/2024
Contact: marjey_lee@163.com
Change Activity:
11/1/2024:
"""
import json

import ll
from projects.monitoring.common.do.alarm import Alarm


def format_alarms(msg):
    """
    _format_alarms
    Args:
        msg:

    Returns:

    """
    if msg['data'] == 1:
        return None
    try:
        data = str(msg['data'], 'utf-8')
        if data.startswith('{'):
            data = json.loads(data)
            data['alarms'] = []
            original_alarms = data['data']
            for item in original_alarms:
                a = Alarm.json_to_obj(item)
                data['alarms'].append(a)
            return data
        else:
            return None
    except Exception as e:
        ll.get_logger().warning(f'Load data to json error:{e}')
        return None
